package fr.afcepf.ai89.esharing.managedbean;

import java.util.ArrayList;
import java.util.List;

import fr.afcepf.ai89.esharing.entity.Emprunt;
import fr.afcepf.ai89.esharing.metier.BusinessEmpruntAem;
import fr.afcepf.ai89.esharing.metier.IBusinessEmpruntAem;

public class PanierManagedBean {
	private List<Emprunt> emprunts = new ArrayList<Emprunt>();
	private List<Boolean> checked = new ArrayList<Boolean>();
	private IBusinessEmpruntAem busEmp = new BusinessEmpruntAem();

	public String valider() {
		for (Emprunt emp : emprunts) {
			busEmp.demanderEmprunt(emp);
		}
		emprunts = new ArrayList<Emprunt>();
		checked = new ArrayList<Boolean>();
		return "index";
	}

	public String retourner() {
		return "";
	}

	public String vider() {
		emprunts = new ArrayList<Emprunt>();
		checked = new ArrayList<Boolean>();
		return "";
	}

	public String supprimer() {
		for (int i = 0; i < checked.size(); i++) {
			//System.out.println(checked.get(i));
			if (checked.get(i)) {
				emprunts.remove(i);
				checked.remove(i);
			}
		}
		return "";
	}
	
	public void addDemande(Emprunt emp){
		emprunts.add(emp);
		checked.add(false);
	}

	public List<Emprunt> getEmprunts() {
		return emprunts;
	}

	public void setEmprunts(List<Emprunt> emprunts) {
		this.emprunts = emprunts;
	}

	public List<Boolean> getChecked() {
		return checked;
	}

	public void setChecked(List<Boolean> checked) {
		this.checked = checked;
	}
	
	

}
